unit SurveyIndexDlg;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, index, nasysutil;


type
  TfrmSurveyIndexDlg = class(TForm)
    ebWeight: TEdit;
    lblType: TLabel;
    Label1: TLabel;
    cbType: TComboBox;
    ebFracF: TEdit;
    Label2: TLabel;
    Label3: TLabel;
    ebFracM: TEdit;
    btnOK: TButton;
    btnCancel: TButton;
    cbObjType: TComboBox;
    lblObjType: TLabel;
    ebMy: TEdit;
    lblMy: TLabel;
    chkPlusGroup: TCheckBox;
    gbBootstrap: TGroupBox;
    lblBootstrapDataSource: TLabel;
    cbBootType: TComboBox;
    lblSigma: TLabel;
    ebSigma: TEdit;
    lblBootFile: TLabel;
    ebBootFile: TEdit;
    procedure btnOKClick(Sender: TObject);
    procedure cbTypeClick(Sender: TObject);
  private
    { Private declarations }
    m_DataSource : TDataSourceObj;
  public
     constructor Create(AOwner : TComponent; SurveyIndex : TDataSourceObj); reintroduce;
    { Public declarations }
  end; // TfrmSurveyIndexDlg

function CreateSurveyIndexDlg(AOwner : TComponent; SurveyIndex : TDataSourceObj) : Boolean;

implementation

{$R *.dfm}

const c_DataSource : array[0..4 - 1] of integer = (odCaNum, odFleet, odSSB, odBiomass);


function CreateSurveyIndexDlg(AOwner : TComponent; SurveyIndex : TDataSourceObj) : Boolean;
var
   frmSurveyIndexDlg : TfrmSurveyIndexDlg;
begin
   frmSurveyIndexDlg := TfrmSurveyIndexDlg.Create(AOwner, SurveyIndex);
   Result := mrOK = frmSurveyIndexDlg.ShowModal;
end; // TfrmSurveyIndexDlg.CreateSurveyIndexDlg


procedure TfrmSurveyIndexDlg.btnOKClick(Sender: TObject);
begin
   m_DataSource.ObservedDataType := c_DataSource[cbType.itemIndex];
   m_DataSource.DataSource.Weight := safestrtofloat(ebWeight.Text);
   m_DataSource.DataSource.My := safestrtofloat(ebMy.Text);
   m_DataSource.DataSource.ObjType := cbObjType.ItemIndex;
   m_DataSource.DataSource.FProp := safestrtofloat(ebFracF.Text);
   m_DataSource.DataSource.MProp := safestrtofloat(ebFracM.Text);
   if chkPlusGroup.Checked then
      m_DataSource.DataSource.PlusGroupCode := 1
   else
      m_DataSource.DataSource.PlusGroupCode := 0;
   m_DataSource.DataSource.BootType := cbBootType.ItemIndex;
   m_DataSource.DataSource.Sigma := safestrtofloat(ebSigma.Text);
   m_DataSource.DataSource.BootFile := ebBootFile.Text;
end; // TfrmSurveyIndexDlg.btnOKClick


procedure TfrmSurveyIndexDlg.cbTypeClick(Sender: TObject);
begin
   ebFracF.Text := '0';
   ebFracM.Text := '0'
end; // TfrmSurveyIndexDlg.cbTypeClick


function ObservedDataTypeToIndex(DataSourceType : Integer) : Integer;
begin
   for Result := 0 to  sizeof(c_DataSource) - 1 do
      if c_DataSource[Result] = DataSourceType then
         exit;
end; // ObservedDataTypeToIndex


constructor TfrmSurveyIndexDlg.Create(AOwner : TComponent; SurveyIndex : TDataSourceObj);
begin
   inherited Create(AOwner);
   m_DataSource := SurveyIndex;
   cbType.ItemIndex := ObservedDataTypeToIndex(m_DataSource.ObservedDataType);
   cbObjType.ItemIndex := m_DataSource.DataSource.ObjType;
   ebWeight.Text := floattostrf(m_DataSource.DataSource.Weight, ffGeneral, 7, 0);
   ebMy.Text := floattostrf(m_DataSource.DataSource.My, ffGeneral, 7, 0);
   ebFracF.Text := floattostrf(m_DataSource.DataSource.FProp, ffGeneral, 7, 0);
   ebFracM.Text := floattostrf(m_DataSource.DataSource.MProp, ffGeneral, 7, 0);
   chkPlusGroup.Enabled := m_DataSource.ObservedDataType = odFleet;
   cbBootType.ItemIndex := m_DataSource.DataSource.BootType;
   ebSigma.Text := floattostrf(m_DataSource.DataSource.Sigma, ffGeneral, 7, 0);
   ebBootFile.Text := m_DataSource.DataSource.BootFile;
   case m_DataSource.ObservedDataType of
      odCanum: chkPlusGroup.Checked := true;
      odSSB, odBiomass: chkPlusGroup.Checked := false;
      odFleet: chkPlusGroup.Checked := m_DataSource.DataSource.PlusGroupCode = 1;
   end; // case
end; // TfrmSurveyIndexDlg.Create


end.
